package com.kitty.game.friend.model;

import com.kitty.common.utils.SpringUtils;
import com.kitty.game.player.model.PlayerProfile;
import com.kitty.game.role.model.Role;
import lombok.Getter;

/**
 * 查看玩家的信息使用
 * 在线时使用Role对象的数据，否则使用PlayerProfile对象的数据
 */
@Getter
public class RoleView {
    private Role role;
    private PlayerProfile playerProfile;

    public RoleView(long uid) {
        this.role = SpringUtils.getRoleService().getOnlinePlayer(uid);
        if (this.role == null) {
            this.playerProfile = SpringUtils.getPlayerService().queryPlayerProfile(uid);
        }
    }

    public RoleView(Role role) {
        if (role == null) {
            throw new IllegalArgumentException("RoleView传入参数role不能为null");
        }
        this.role = role;
    }

    public boolean isOnline() {
        return role != null;
    }

    public long getUid() {return role != null ? role.getUid() : playerProfile.getGid();}

    public String getGid() {return role != null ? role.getGid() : String.valueOf(playerProfile.getGid());}

    public int getRoleId() {return role != null ? role.getRoleId() : playerProfile.getRoleId();}

    public String getName() {
        return role != null ? role.getName() : playerProfile.getName();
    }

    public short getRoleIcon() {
        return role != null ? role.getRoleIcon() : playerProfile.getRoleIcon();
    }

    public short getLevel() {
        return role != null ? role.getLevel() : playerProfile.getLevel();
    }

    public int getWeaponIcon() {
        return role != null ? role.getWeaponIcon() : playerProfile.getWeaponIcon();
    }

    public String getPartyName() {
        return role != null ? role.getPartyName() : playerProfile.getPartyName();
    }

    public short getPolar() {
        return role != null ? role.getPolar() : playerProfile.getPolar();
    }

    public String getCurrTitle() {
        return role != null ? role.getCurrTitle() : playerProfile.getCurrTitle();
    }

    public byte getGender() {return role != null ? role.getGender() : playerProfile.getGender(); }

    public int getTao() {return role != null ? role.getTao() : playerProfile.getTao(); }
}
